package utils;

/**
 * 功能描述:阵列使用情况
 * 2024/08/21
 *
 * @author ZhangYi
 */
public class arrayUtils {

	/**
	 * 一维数组
	 *
	 * @return {@code int[] }
	 * @author ZhangYi
	 */
	public static int[] oneDimensionalArray(){
		return new int[]{123,12,3123,1231123,123};
	}

	/**
	 * 二维数组
	 *
	 * @return {@code int[][] }
	 * @author ZhangYi
	 */
	public static int[][] twoDimensionalArray(){
		int[][] arr = new int[3][4];
		for (int i = 0; i < arr.length;i++){
			for (int j =0;j < arr[0].length;j++){
				arr[i][j]=-1;
			}
		}
		return arr;
	}

	/**
	 * 三维阵列
	 *
	 * @return {@code int[][][] }
	 * @author ZhangYi
	 */
	public static int[][][] threeDimensionalArray(){
		int[][][] arr = new int[3][4][5];
		for (int i = 0; i < arr.length;i++){
			for (int j =0;j < arr[0].length;j++){
				for (int k =0;k < arr[0][0].length;k++){
					arr[i][j][k]= -1;
				}
			}
		}
		return arr;
	}

	/**
	 * 四维数组
	 *
	 * @return {@code int[][][][] }
	 * @author ZhangYi
	 */
	public static int[][][][] fourDimensionalArray(){
		int[][][][] arr = new int[3][4][5][6];
		for (int i = 0; i < arr.length;i++){
			for (int j =0;j < arr[0].length;j++){
				for (int k =0;k < arr[0][0].length;k++){
					for (int l =0;l < arr[0][0][0].length;l++){
						arr[i][j][k][l]= -1;
					}
				}
			}
		}
		return arr;
	}

	public static void main(String[] args) {
		// 类似图书馆?
		// 一维数组
		int[] oneDimensionalArray = oneDimensionalArray();
		System.out.println(String.format("一维数组 元素个数 %d",oneDimensionalArray.length));

		// 二维数组
		int[][] twoDimensionalArray = twoDimensionalArray();
		System.out.println(String.format(" 二维数组的行为 %d 行,列为 %d 列",twoDimensionalArray.length,twoDimensionalArray[0].length));

		// 三维数组
		int[][][] threeDimensionalArray = threeDimensionalArray();
		System.out.println(String.format(" 三维数组的行为 %d 行,列为 %d 列,为 %d 层",threeDimensionalArray.length,threeDimensionalArray[0].length,threeDimensionalArray[0][0].length));

		// 四维数组
		int[][][][] fourDimensionalArray = fourDimensionalArray();
		System.out.println(String.format(" 四维数组的行为 %d 行,列为 %d 列,为 %d 层,为 %d 层",fourDimensionalArray.length,fourDimensionalArray[0].length,fourDimensionalArray[0][0].length,fourDimensionalArray[0][0][0].length));
	}
}
